package com.fgou.springcloud.controller;


import com.fgou.springcloud.pojo.Dept;
import com.fgou.springcloud.util.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

/**
 * @author 99
 */
@RestController
@RequestMapping(value = "/consumer/dept",produces = "application/json; charset=UTF-8")
public class DeptConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/list")
    public List<Dept> getDeptAll() {
        return restTemplate.getForObject(Context.getURL.REST_UL_PREFIX_DEPT + "/list", List.class);
    }

    @GetMapping("/get/{id}")
    public Dept getDeptById(@PathVariable(value = "id") Long id) {
        return restTemplate.getForObject(Context.getURL.REST_UL_PREFIX_DEPT + "/get/" + id, Dept.class);
    }

    @PostMapping("/add")
    public Boolean addDeptOne(@RequestBody Map<String, String> map) {
        System.out.println(map.get("deptName"));
        return restTemplate.postForObject(Context.getURL.REST_UL_PREFIX_DEPT + "/add",map, Boolean.class);
    }
}
